<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\Admin;
use app\common\model\Order as OrderModel;


class Groupon extends Admin {


  public function account() {
    //查找团购订单
    $map = $this->createMap();
    $count = OrderModel::where($map)->count();

    //从订单中查询商品列表
    //$slist = db('order_shoplist')->alias('s')->where($map)->join('order o','s.order_id = o.id','RIGHT')->field('sum(num*price) as priceSum,rule_id,good_name,rule_name,sum(num) as onum')->group('rule_id')->order('onum desc')->select();

     $list =  OrderModel::where($map)->alias('o')->join('order_shoplist s','s.order_id = o.id','RIGHT')->field('sum(num*price) as priceSum,rule_id,good_name,rule_name,sum(num) as onum')->group('good_name')->order('onum desc')->select();
     $count =OrderModel::where($map)->alias('o')->join('order_shoplist s','s.order_id = o.id','RIGHT')->sum('num*price');


    $this->assign('list', $list);
    $this->assign('count', $count);
    $this->setMeta('商品总算');
		return $this->fetch();
	}

  public function createMap(){
      input('out_trade_no') ? $map['out_trade_no'] = array('like', '%'.input('out_trade_no').'%') : '';
      input('wxname') ? $map['nick_name'] = array('like', '%'.input('wxname').'%') : '';
      input('rebate_code') ? $map['rebate_code'] = input('rebate_code') : '';
      input('pay') ? $map['pay'] = input('pay') : '';
      input('buystatus') ? $map['buystatus'] = input('buystatus') : '';
      if(input('start') && input('end')){
          $map['create_time'] = array('between time', [input('start'), input('end')]);
          $map['buystatus'] = array('gt','0');
      }
      $map['index_type'] = 1; //
      return $map;
  }

}

 ?>
